<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="/templates/ui.xhtml">

<ui:define name="head">
    <title>报备资料维护界面</title>
    <script type="text/javascript" src="#{request.contextPath}/UI/support/pub.js"/>
    <script type="text/javascript" language="javascript">
        document.onkeydown = function TabReplace() {
            if (event.keyCode == 13) {
                if (event.srcElement.tagName != 'BUTTON')
                    event.keyCode = 9;
                else
                    event.srcElement.click();
            }
        }
    </script>
</ui:define>
<ui:define name="content">
<h:form id="form" enctype="multipart/form-data">
<p:focus for="id"/>
<p:growl id="msgs" showDetail="true"/>
<p:panel id="ppCondition" style="width: 100%">
    <h:panelGrid columns="2" style="width: 100%;">
        <h:panelGrid id="pgCust" widgetVar="WvCust" columns="6" style="text-align: right;">
            <h:outputLabel value="纳税人识别号:" for="id" style="font-weight: bold;"/>
            <p:inputText id="id" value="#{enterResouceBackupAction.taxpayerId}"/>

            <h:outputLabel value="项目名称:" for="pname" style="font-weight: bold;margin-left: 100px;"/>
            <p:inputText id="pname" value="#{enterResouceBackupAction.projectName}"/>
        </h:panelGrid>
        <h:panelGrid style="width:10%">
            <p:commandButton id="create" value="增加" actionListener="#{enterResouceBackupAction.add()}"
                             style="font-size: 14px;width: 80px;" update=":form:tabSum,:form:pname,msgs"/>
        </h:panelGrid>
    </h:panelGrid>
</p:panel>

<p:ajaxStatus style="width:16px;height:16px;">
    <f:facet name="start">
        <h:graphicImage value="/images/ajaxloading.gif"/>
    </f:facet>
    <f:facet name="complete">
        <h:outputText value=""/>
    </f:facet>
</p:ajaxStatus>

<p:contextMenu for="tabSum">
    <p:menuitem value="上传附件" icon="ui-icon-plus" oncomplete="uploadAttachement.show()"/>
    <p:menuitem value="删除" icon="ui-icon-close" actionListener="#{enterResouceBackupAction.deleteProject()}"
                update=":form:tabSum,:form:tabDetail"/>
</p:contextMenu>

<p:dataTable id="tabSum" style="width:100%;"
             value="#{enterResouceBackupAction.thebrsList}"
             var="thebrs"
             rowKey="#{thebrs.pkid}"
             selectionMode="single"
             selection="#{enterResouceBackupAction.thebrsSelected}"
             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks}
              {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
             paginator="true"
             paginatorPosition="bottom"
             rows="15"
             rowsPerPageTemplate="100,50,30,15,5"
             emptyMessage="数据记录为空..." rowIndexVar="index">
    <p:ajax event="rowSelect" listener="#{enterResouceBackupAction.getAllThebrds()}" update=":form:tabDetail"/>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="序号"/>
        </f:facet>
        <h:outputText value="#{index + 1}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{thebrs.taxpayer_id}">
        <f:facet name="header">
            <h:outputText value="纳税人识别号"/>
        </f:facet>
        <h:outputText value="#{thebrs.taxpayer_id}"/>
    </p:column>

    <p:column style="text-align:center" filterBy="#{thebrs.taxpayer_name}" filterMatchMode="contains">
        <f:facet name="header">
            <h:outputText value="纳税人名称"/>
        </f:facet>
        <h:outputText value="#{thebrs.taxpayer_name}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{thebrs.project_id}">
        <f:facet name="header">
            <h:outputText value="项目编号"/>
        </f:facet>
        <h:outputText value="#{thebrs.project_id}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{thebrs.project_name}">
        <f:facet name="header">
            <h:outputText value="开发项目"/>
        </f:facet>
        <h:outputText value="#{thebrs.project_name}"/>
    </p:column>

    <p:column style="text-align:center;" sortBy="#{thebrs.resource_num}">
        <f:facet name="header">
            <h:outputText value="备案资料(份数)"/>
        </f:facet>
        <h:outputText value="#{thebrs.resource_num}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{thebrs.accepter}">
        <f:facet name="header">
            <h:outputText value="受理人"/>
        </f:facet>
        <h:outputText value="#{thebrs.accepter}"/>
        <f:facet name="footer">
            <h:outputText value="笔数：#{fn:length(enterResouceBackupAction.thebrsList)}"/>
        </f:facet>
    </p:column>

    <p:column style="text-align:center" sortBy="#{thebrs.accept_date}">
        <f:facet name="header">
            <h:outputText value="受理日期"/>
        </f:facet>
        <h:outputText value="#{thebrs.accept_date}">
            <f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8" locale="cn"></f:convertDateTime>
        </h:outputText>
        <f:facet name="footer">
            <h:commandLink>
                <h:outputText value="[导出数据]"/>
                <p:dataExporter type="xls" target="tabSum" fileName="qybbzltjb"/>
            </h:commandLink>
        </f:facet>
    </p:column>

</p:dataTable>
<p:separator/>
<p:dataTable id="tabDetail" style="width:100%;"
             value="#{enterResouceBackupAction.thebrdList}"
             var="thebrd"
             rowKey="#{thebrd.pkid}"
             selectionMode="single"
             selection="#{enterResouceBackupAction.thebrdSelected}"
             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks}
              {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
             paginator="true"
             paginatorPosition="bottom"
             rows="15"
             rowsPerPageTemplate="100,50,30,15,5"
             emptyMessage="数据记录为空..." rowIndexVar="index">

    <f:facet name="header">
        <h:outputText value="附件列表"/>
    </f:facet>
    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="序号"/>
        </f:facet>
        <h:outputText value="#{index + 1}"/>
    </p:column>

    <p:column style="text-align:center;" sortBy="#{thebrd.resource_code}">
        <f:facet name="header">
            <h:outputText value="资料代码"/>
        </f:facet>
        <h:outputText value="#{thebrd.resource_code}"/>
    </p:column>

    <p:column style="text-align:center" filterBy="#{thebrd.resource_name}" filterMatchMode="contains">
        <f:facet name="header">
            <h:outputText value="备案资料"/>
        </f:facet>
        <h:outputText value="#{thebrd.resource_name}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{thebrd.idNo}">
        <f:facet name="header">
            <h:outputText value="证件号码"/>
        </f:facet>
        <h:outputText value="#{thebrd.idNo}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{thebrd.inputer}">
        <f:facet name="header">
            <h:outputText value="录入人"/>
        </f:facet>
        <h:outputText value="#{thebrd.inputer}"/>
    </p:column>

    <p:column style="text-align:center" sortBy="#{thebrd.input_date}">
        <f:facet name="header">
            <h:outputText value="录入日期"/>
        </f:facet>
        <h:outputText value="#{thebrd.input_date}">
            <f:convertDateTime pattern="yyyy-MM-dd" timeZone="GMT+8" locale="cn"></f:convertDateTime>
        </h:outputText>
    </p:column>

    <p:column style="text-align:center" sortBy="#{thebrd.file_name}">
        <f:facet name="header">
            <h:outputText value="位图文件名称"/>
        </f:facet>
        <h:outputText value="#{thebrd.file_name}"/>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="预览"/>
        </f:facet>
        <p:commandLink actionListener="#{enterResouceBackupAction.preview(thebrd.file_name)}" update=":form:preimage"
                       oncomplete="preview.show()">
            <h:outputText value="预览"/>
        </p:commandLink>
    </p:column>

    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="下载"/>
        </f:facet>
        <p:commandLink id="download" actionListener="#{enterResouceBackupAction.download()}" ajax="false">
            <f:param name="taxpayer_id" value="#{thebrd.taxpayer_id}"/>
            <f:param name="project_id" value="#{thebrd.project_id}"/>
            <f:param name="file_name" value="#{thebrd.file_name}"/>
            <f:param name="resource_name" value="#{thebrd.resource_name}"/>
            <p:graphicImage alt="下载" value="/images/download.png" style="border: 0"/>
            <p:fileDownload value="#{enterResouceBackupAction.downloadFile}"/>
        </p:commandLink>
        <f:facet name="footer">
            <h:outputText value="笔数：#{fn:length(enterResouceBackupAction.thebrdList)}"/>
        </f:facet>
    </p:column>
    <p:column style="text-align:center">
        <f:facet name="header">
            <h:outputText value="删除"/>
        </f:facet>
        <p:commandLink id="delete" actionListener="#{enterResouceBackupAction.delete()}" ajax="false"
                       update=":form:tabSum,:form:tabDetail">
            <f:param name="pkid" value="#{thebrd.pkid}"/>
            <f:param name="taxpayer_id" value="#{thebrd.taxpayer_id}"/>
            <f:param name="project_id" value="#{thebrd.project_id}"/>
            <f:param name="file_name" value="#{thebrd.file_name}"/>
            <p:graphicImage alt="删除" value="/images/delete.jpg" style="border: 0"/>
        </p:commandLink>
        <f:facet name="footer">
            <h:commandLink>
                <h:outputText value="[导出数据]"/>
                <p:dataExporter type="xls" target="tabDetail" fileName="qybbzlmxb"/>
            </h:commandLink>
        </f:facet>
    </p:column>
</p:dataTable>

<p:dialog id="uploadAttachement" widgetVar="uploadAttachement" header="上传附件" showEffect="drop"
          hideEffect="drop" style="text-align: center;">
    <h:panelGrid columns="2">
        <h:outputLabel value="资料代码:" for="resourceCode" style="font-weight: bold;"/>
        <p:inputText id="resourceCode" value="#{enterResouceBackupAction.resourceCode}"/>
        <h:outputLabel value="证件号码:" for="idno" style="font-weight: bold;"/>
        <p:inputText id="idno" value="#{enterResouceBackupAction.idNo}"/>
        <h:outputLabel value="选择文件:" for="fileName" style="font-weight: bold;"/>
        <p:fileUpload id="fileName" value="#{enterResouceBackupAction.uploadedFile}" mode="simple"
                      style="width: 153px;"/>
    </h:panelGrid>
    <p:commandButton value="上传" ajax="false" actionListener="#{enterResouceBackupAction.add2()}"
                     update=":form:attachementList,:form:tabSum"/>
</p:dialog>

<p:dialog id="preview" widgetVar="preview" header="预览文件" showEffect="drop"
          hideEffect="drop" style="text-align: center;"  modal="true">
    <p:graphicImage id="preimage" value="#{enterResouceBackupAction.selectFileName}"/>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>